var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("PromoNodeArrItem"),
i = cc._decorator,
a = i.ccclass,
r = i.property,
s = function(e) {
    __extends(t, e);
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        t.mDatas = null;
        t.itemList = [];
        t.prefab = null;
        t.layout = null;
        t.move = null;
        t.show = null;
        t.hide = null;
        t.maskNode = null;
        t.maxX = 640;
        t.oppoClose = !1;
        t.offsetWidth = 15;
        t.offsetHeight = 10;
        t.moveSpeed = 80;
        t.targetX = 0;
        return t
    }
    t.prototype.onLoad = function() {
        SDK.Base.Event.on("getData", this.initData, this);
        this.initData()
    };
    t.prototype.onDestroy = function() {
        SDK.Base.Event.off("getData", this.initData, this)
    };
    t.prototype.initData = function() {
        if (SDK.Mgr.Inst.hasPromoData && (SDK.Mgr.Inst.curChannel != SDK.Define.Channel.oppo || SDK.Mgr.Inst.isAdOpen)) {
            this.node.active = !0;
            this.mDatas = Config.Base.promoData;
            this.setData()
        } else this.node.active = !1
    };
    t.prototype.setData = function() {
        var e = this.mDatas.content.length;
        if (e > 0) for (var t = 0,
        n = 0; n < 3; n++) for (var i = 0; i < e; i++) {
            var a = cc.instantiate(this.prefab);
            a.parent = this.layout;
            a.active = !0;
            var r = a.getComponent(o.default);
            null != r && this.itemList.push(r);
            r.setData(this.mDatas.content[i]);
            var s = (t % 3 - 1) * (a.width + this.offsetWidth),
            c = (1 - Math.floor(t / 3)) * (a.height + this.offsetHeight);
            a.setPosition(s, c);
            t++
        }
    };
    t.prototype.update = function(e) {
        for (var t = this.mDatas.content.length,
        n = 0; n < this.itemList.length; n++) {
            this.itemList[n].pNode.setPosition(this.itemList[n].pNode.position.x, this.itemList[n].pNode.position.y + e * this.moveSpeed);
            if (this.itemList[n].pNode.position.y > 2 * (this.prefab.width + this.offsetWidth)) {
                var o = this.itemList[n].pNode.position.y - t * (this.prefab.height + this.offsetHeight);
                this.itemList[n].pNode.setPosition(this.itemList[n].pNode.x, o)
            }
        }
        if (this.move.position.x != this.targetX) {
            var i = this.targetX - this.move.position.x,
            a = 3e3 * e;
            i = i > 0 ? Math.min(this.move.position.x + a, this.targetX) : Math.max(this.move.position.x - a, this.targetX);
            this.move.position = new cc.Vec3(i, 0);
            if (0 == this.move.position.x) {
                this.show.active = !0;
                this.hide.active = !1
            }
        }
    };
    t.prototype.Show = function() {
        this.targetX = this.maxX;
        this.show.active = !1;
        this.hide.active = !0;
        if (this.maskNode) {
            this.maskNode.active = !0;
            this.maskNode.opacity = 0;
            this.maskNode.runAction(cc.fadeTo(.3, 180))
        }
    };
    t.prototype.Hide = function() {
        var e = this;
        this.targetX = 0;
        this.maskNode && this.maskNode.runAction(cc.sequence(cc.fadeOut(.3), cc.callFunc(function() {
            e.maskNode.active = !1
        })))
    };
    __decorate([r(cc.Node)], t.prototype, "prefab", void 0);
    __decorate([r(cc.Node)], t.prototype, "layout", void 0);
    __decorate([r(cc.Node)], t.prototype, "move", void 0);
    __decorate([r(cc.Node)], t.prototype, "show", void 0);
    __decorate([r(cc.Node)], t.prototype, "hide", void 0);
    __decorate([r(cc.Node)], t.prototype, "maskNode", void 0);
    __decorate([r(cc.Boolean)], t.prototype, "oppoClose", void 0);
    __decorate([r(cc.Float)], t.prototype, "offsetWidth", void 0);
    __decorate([r(cc.Float)], t.prototype, "offsetHeight", void 0);
    __decorate([r(cc.Float)], t.prototype, "moveSpeed", void 0);
    return __decorate([a], t)
} (cc.Component);
n.default = s